﻿using System.Collections.Generic;
using System.Data.Entity.Core.Mapping;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure;
using Sharp.Infrastructure.Interfaces;

namespace Sharp.Domain.CMSBoundedContext
{
    public class Bootstraper : IBootstrapPlugin
    {
        public void Initialize()
        {
            using (Entities dbContext = new Entities())
            {
                var objectContext = ((IObjectContextAdapter)dbContext).ObjectContext;

                var mappingCollection =
                    (StorageMappingItemCollection)objectContext.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
                mappingCollection.GenerateViews(new List<EdmSchemaError>());
            }
            this.IsAlready = true;
        }

        public bool IsAlready { get; set; }
    }
}